package openase.audiosearch.comm.response.encoder;

import java.nio.ByteBuffer;

import openase.audiosearch.comm.StringFormatUtils;
import openase.audiosearch.comm.response.ExecutionError;
import openase.audiosearch.comm.response.ResponseType;


public class ExecutionErrorResponseEncoder implements ResponseEncoder<ExecutionError> {

	public ByteBuffer encode(ExecutionError response) {
		byte[] errorMessage = StringFormatUtils.getUtf8(response.getErrorMessage());

		ByteBuffer buffer = ByteBuffer.allocate(1 + 4 + errorMessage.length);
		buffer.put(ResponseType.EXECUTION_ERROR.getId());
		buffer.putInt(errorMessage.length);
		buffer.put(errorMessage);

		return buffer;
	}

}
